<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
    <ui:composition template="/resources/templates/default.xhtml">
        <ui:define name="title">Scan de logs</ui:define>
        <ui:define name="titlePage">Scan de logs</ui:define>
        <ui:define name="content">
            <p:layout>
                <p:layoutUnit position="north">
                    <p:panel header="Description">
                        Ce module permet d'envoyer et d'analyser des fichiers de logs existants depuis votre ordinateur.
                        <br/>
                        Ce processus peut être long amis ne s'interrompt pas tant que votre session reste ouverte.
                    </p:panel>
                </p:layoutUnit>
                <p:layoutUnit position="east" size="400">
                    <p:panel id="panel_status" header="Scan">
                        <h:form id="statusScanForm">
                            <p:panel style="margin-bottom: 10px; padding:0;">
                                <p:panel style="background:lightslategrey; display: inline-block;">
                                    <span style="color:white;">Infos</span>
                                </p:panel>
                                <h:outputText style="padding-left:10px;" id="infos_message" value="#{scanLogsBean.infosMessage}" />
                            </p:panel>
                            <p:panel header="Configuration de votre serveur de logs">
                                <p:panelGrid columns="2" style="width:100%;">
                                    <h:outputText value="Adresse IP : " /><h:outputText value="#{scanLogsBean.logsServerIp}" />
                                    <h:outputText value="Utilisateur : " /><h:outputText value="#{scanLogsBean.logsServerUser}" />
                                    <h:outputText value="Mot de passe : " /><h:outputText value="***********" />
                                    <h:outputText value="Répertoire : " /><h:outputText value="#{scanLogsBean.logsServerPath}" />
                                </p:panelGrid>
                            </p:panel>
                        </h:form>

                        <h:form id="avctScanForm">
                            <p:outputLabel value="Avancement" style="padding:10px;">
                                <p:progressBar styleClass="animated" labelTemplate="{value}%" id="progress_value" value="#{scanLogsBean.fileToAnalyse.avancement}"/>
                            </p:outputLabel>
                        </h:form>

                        <p:panel style="text-align:center;">
                            <h:form id="scanStartForm">
                                <p:commandButton disabled="#{scanLogsBean.status &lt; 0}" id="scan_button" value="Récupérer la liste des fichiers de logs" update=":statusScanForm:infos_message" actionListener="#{scanLogsBean.scan()}" />
                            </h:form>
                        </p:panel>
                        <p:panel header="Analyse des logs">
                            <h:form id="analyseStartForm">
                                <p:commandButton disabled="#{empty scanLogsBean.fileToScan}}" id="analyse_button" value="Commencer" actionListener="#{scanLogsBean.analyse()}" />
                                <p:commandButton disabled="#{scanLogsBean.status != 3}" value="Metre en pause" actionListener="#{scanLogsBean.stopAnalyse()}" />
                            </h:form>
                        </p:panel>
                    </p:panel>
                </p:layoutUnit>
                <p:layoutUnit position="center">
                    <p:panel header="Envoi des fichiers de logs">
                        <h:form>
                            <p:fileUpload cancelLabel="Annuler" label="Choisir un fichier de logs" uploadLabel="Scanner" invalidFileMessage="Type de fichier invalide (*.log)" fileUploadListener="#{fileUploadBean.uploadLogs}" mode="advanced" dragDropSupport="true"
                                          update=":growl" sizeLimit="1000000000" fileLimit="30" allowTypes="/(\.|\/)(log)$/" />
                        </h:form>
                    </p:panel>
                    <h:form id="analyseFilesForm">
                        <p:commandButton value="Analyser" actionListener="#{scanLogsBean.analyse()}" id="buttonAnalyse" disabled="#{scanLogsBean.filesToAnalyse.size() eq 0}" />
                        <p:dataTable id="listLogsFiles" emptyMessage="Aucun fichier de logs n'a été importé" style="font-size: 11px;" var="file" value="#{scanLogsBean.filesToAnalyse}">
                            <p:column headerText="Nom du fichier">
                                        #{file.filename}
                            </p:column>

                            <p:column headerText="Date de début">
                                        #{file.startDate}
                            </p:column>

                            <p:column headerText="Date de fin">
                                        #{file.endDate}
                            </p:column>

                            <p:column headerText="Nb. logs">
                                        #{file.nbLignes}
                            </p:column>

                            <p:column headerText="Status">
                                <h:outputText id="#{file.filename}_nlidb" value="#{file.nbLigneInsertDB}" />
                            </p:column>
                            
                            <p:column headerText="Action" style="text-align:center;">
                                <p:commandButton style="width:30px; height:30px;" value="" icon="ui-icon-close" actionListener="#{scanLogsBean.removeFile(file)}"/>
                            </p:column>
                        </p:dataTable>
                    </h:form>
                </p:layoutUnit>
            </p:layout>
        </ui:define>
        <ui:define name="dialogs">
            <p:blockUI block=":panel_status" trigger=":scanStartForm:scan_button">
                Récupération de la liste des fichiers distants en cours ...
            </p:blockUI>
        </ui:define>
    </ui:composition>
</html>
